<script>
	import { getwechatUrl} from './api/user.js'
	export default {
		onLaunch: function() {
			this.getUserInfo()
			this.$store.dispatch('getCity', this)
		 const code = this.getUrlCode('code')
		 if (!code) {
		 	this.getUrl()
		 }  

		},
		onShow: function() {
			 const code = this.getUrlCode('code')
			if (!code) {
				this.getUrl()
			}  
		},
		onHide: function() {
		},
		methods: {
			// 获取code
			getUrlCode (name) {
				let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
						let r = window.location.search.substr(1).match(reg);
						if (r != null) {
							return unescape(r[2]);
						}
						return null
			},
			// 获取用户信息
			getUserInfo () {
				const userinfo = uni.getStorageSync('userinfo')  || ''
				const userCount = uni.getStorageSync('userCount') || ''
				this.$store.commit('setInfo', userinfo)
				this.$store.commit('setUserNum', userCount)
			},
			// 获取授权网页
			async getUrl () {
				 // 微信授权
				 const url = await getwechatUrl()
				 window.location.href = url.data.data.url 
			},
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "./static/css/global.scss";
	/* uview组件样式库  */
	@import "uview-ui/index.scss";
	/* 字体图标 */
	@import "./static/css/iconfont.scss";
</style>
